/*This program will run regressions of the ECLS-K transformations test gap 
with the F/L controls*/


clear all

set mem 300m
set more off
/*Choose data directory here*/
cd "C:\Users\bond10\Desktop\RA\Test Scores\Paper\replication files"
use ECLSbondlang.dta, clear


local flcontrols = "hispanic asian other birthweight missingbirthweight female books books2 missingbooks momover30 teenmom missingmombirth ses missingses wic missingwic"

/*baseline*/

foreach x in fallk springk spring1 spring3  {
qui: reg read`x'std black age`x' `flcontrols' [pweight=weights], robust
est sto A`x'                                        
   }
est tab Afallk Aspringk Aspring1 Aspring3, keep(black) b se
   
/*Minimizing Transformation*/
scalar B1 = 59.8183438089138
scalar B2 = -150.712988667491
scalar B3 = 133.052138026368
scalar B4 = -654.160995681869
scalar B5 = 1307.7864463404
scalar B6 = 1078.9278199586
scalar k = -0.3414266539
scalar N1 = -47.1499167878298

/*apply normalization*/
replace readspring3 = readspring3/180
replace readfallk = readfallk/180
replace readspringk = readspringk/180
replace readspring1 = readspring1/180

foreach x in fallk springk spring1 spring3         {
gen mintransform`x' = B1*(read`x' + k) + B2*(read`x' + k)^2 + B3*(read`x' + k)^3 + B4*(read`x' + k)^4 + B5*(read`x' + k)^5 + B6*(read`x' + k)^6 - N1
                                                       }
foreach x in fallk springk spring1 spring3  {
qui: summ mintransform`x' [aweight=weights]
scalar mn = r(mean)
scalar stnd = r(sd)
gen mintransform`x'std = (mintransform`x'-mn)/stnd
qui: reg mintransform`x'std black age`x' `flcontrols' [pweight=weights], robust
est sto B`x'
                                        }
										
est tab Bfallk Bspringk Bspring1 Bspring3, keep(black) b se
                                         
/*Maximizing Transformation*/
scalar B1 = 43.799320378222
scalar B2 = 335.609232031174
scalar B3 = 688.559923214134
scalar B4 = -1096.7722196637
scalar B5 = -476.790031091736
scalar B6 = 626.360970505262
scalar k = -0.2784345
scalar N1 = -16.4208945492854

foreach x in fallk springk spring1 spring3         {
gen maxtransform`x' = B1*(read`x' + k) + B2*(read`x' + k)^2 + B3*(read`x' + k)^3 + B4*(read`x' + k)^4 + B5*(read`x' + k)^5 + B6*(read`x' + k)^6 - N1
                                                       }
foreach x in fallk springk spring1 spring3  {
qui: summ maxtransform`x' [aweight=weights]
scalar mn = r(mean)
scalar stnd = r(sd)
gen maxtransform`x'std = (maxtransform`x'-mn)/stnd
qui: reg maxtransform`x'std black age`x' `flcontrols' [pweight=weights], robust

est sto C`x'
}

est tab Cfallk Cspringk Cspring1 Cspring3, keep(black) b se

/*Fall-K R2 Transformation*/
scalar B1 = 2959.23268775735
scalar B2 = 12710.2673064966
scalar B3 = 29460.2745370992
scalar B4 = 36857.0819681668
scalar B5 = 23279.9123969347
scalar B6 = 5752.4599459532
scalar k = -1.158344
scalar N1 = -428.334127060023

foreach x in fallk springk spring1 spring3         {
gen r2transform`x' = B1*(read`x' + k) + B2*(read`x' + k)^2 + B3*(read`x' + k)^3 + B4*(read`x' + k)^4 + B5*(read`x' + k)^5 + B6*(read`x' + k)^6 - N1
                                                       }
foreach x in fallk springk spring1 spring3  {
qui:summ r2transform`x' [aweight=weights]
scalar mn = r(mean)
scalar stnd = r(sd)
gen r2transform`x'std = (r2transform`x'-mn)/stnd
qui: reg r2transform`x'std black age`x' `flcontrols' [pweight=weights], robust
est sto D`x'
}

est tab Dfallk Dspringk Dspring1 Dspring3, keep(black) b se
